package com.gblfy.lyrabbitmq.provider;

import com.alibaba.fastjson.JSON;
import com.gblfy.common.entity.Order;
import com.gblfy.lyrabbitmq.consts.MQPrefixConst;
import com.gblfy.lyrabbitmq.utils.MQSendMsgUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * RabbitMQ发送消息
 *
 * @author gblfy
 * @Date 2021-09-28 9:59
 */
@Service
public class RabbitMQProvider {
    private final static Logger log = LoggerFactory.getLogger(RabbitMQProvider.class);

    @Autowired
    private MQSendMsgUtils mqSendMsgUtils;

    /**
     * 发送补偿MQ消息
     *
     * @param orderId    订单编码
     * @param orderNum   订单数量
     * @param createTime 订单时间
     * @return 发送标识
     */
    public void sendMQContent(long orderId, String orderNum, LocalDateTime createTime) {
        Order order = Order.builder()
                .orderId(orderId)
                .orderNum(orderNum)
                .createTime(createTime)
                .build();
        // 发送MQ消息到交换机通过指定消息路由key路由到指定队列中
        mqSendMsgUtils.snedStrMQMsg(MQPrefixConst.LY_MQ_FAI_QUERY, JSON.toJSONString(order));
        log.info("MQ消息发送成功");
    }
}
